##
##	Ändra databas inställningar
##	TOD: Fixa stöd för att genera grafer för enskilda projekt.
##
## usage: R < plot.r --save abiword
#
#

library(RMySQL)
con <- dbConnect(dbDriver("MySQL"), user="root",
                 password="reload", dbname="x90test")

args <- commandArgs()
name <-args[3]

# Get commits from database.
query <- paste("SELECT date, rev, count(s.rev) as commits FROM log as s where s.project='",name,"' group by date_format(s.date,'%Y%m')
", sep="");
res <- dbGetQuery(con,query)

# Plot activity
png(paste(name,"commits",".png"), width = 320, height = 320, units = "px")
plot(strptime(res$date,"%Y-%m-%d"),res$commits, type="l", xlab="Date", ylab="Commits",
     main=paste(name,"count(log.date) per month"))

# Get comment density from database
query <- paste("select date, sum(comment)/sum(code) as totaldensity, log.rev from filemetric, log where log.rev=filemetric.rev and filemetric.project='",name,"' and log.project='",name,"' group by date_format(log.date,'%Y%m') order by date asc", sep="");
results <- dbGetQuery(con,query)
#print(results)

png(paste(name,"density",".png"), width = 320, height = 320, units = "px")
plot(strptime(results$date,"%Y-%m-%d"),results$totaldensity, type="l", xlab="Date", ylab="Density", ylim=c(0,0.8),
     main=paste(name,"sum(comment)/sum(code) per month"))

dev.off()
